1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2014 Devisualization (Richard Andrew Cattermole)
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 module devisualization.util.opengl.shaders.solidcolor;
25 import devisualization.util.opengl.shaders.defs;
26 import devisualization.util.opengl.vertexarray;
27 import devisualization.util.opengl.buffers;
28 import devisualization.image.color;
29 import gl3n.linalg : vec4, mat4;
30 deprecated("de_util:opengl is going to die"):
31 
32 /**
33  * Renders vertices as a solid colour
34  * 
35  * Shader based upon https://github.com/fogleman/pg/blob/master/pg/programs.py
36  */
37 class SolidColorShader : ShaderProgram {
38 	this() {
39 		super("""
40 #if __VERSION__ > 120
41     #version 130
42     in vec4 position;
43 #else
44     #version 120
45     attribute vec4 position;
46 #endif
47 
48 uniform vec4 move;
49 uniform mat4 scale;
50 uniform mat4 transform;
51 
52 void main() {
53     gl_Position = ((scale * position) + move) * transform;
54 }
55 			""",
56 			"""
57 #if __VERSION__ > 120
58     #version 130
59     uniform vec4 color;
60 
61     out vec4 outColor;
62     void main() {
63         outColor = color;
64     }
65 #else
66     #version 120
67     uniform vec4 color;
68 
69     void main() {
70         gl_FragColor = color;
71     }
72 #endif
73 		""");
74 
75 		myColor = Color_RGBA(1f, 1f, 1f, 1f);
76 	}
77 
78 	@disable {
79 		this(string vert, string frag=null, string geom=null){}
80 		this(Shader vert = null, Shader frag = null, Shader geom = null){}
81 	}
82 
83 	@property {
84 		void myColor(Color_RGBA c) {
85 			uniform("color", vec4(c.r, c.g, c.b, c.a));
86 		}
87 
88 		void move(vec4 v) {
89 			uniform("move", v);
90 		}
91 
92 		void scale(mat4 m) {
93 			uniform("scale", m);
94 		}
95 
96 		void transform(mat4 m) {
97 			uniform("transform", m);
98 		}
99 
100 		void myVertices(VertexArray vao, IBuffer buffer) {
101 			import devisualization.util.opengl.function_wrappers.v20 : AttribPointerType;
102 			vao.bindAttribute(this, "position", buffer, AttribPointerType.Float, 4);
103 		}
104 	}
105 }